# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Prokop Randáček <prokop@rdck.dev>
pkgname=cutechess
pkgver=1.3.1
pkgrel=0
pkgdesc="GUI, CLI and library for playing chess"
url="https://cutechess.com"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	cmake
	qt6-qt5compat-dev
	qt6-qtbase-dev
	qt6-qtsvg-dev
	samurai
	"
subpackages="
	$pkgname-doc:cutechess_doc:noarch
	$pkgname-cli
	$pkgname-cli-doc:cli_doc:noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/cutechess/cutechess/archive/refs/tags/v$pkgver.tar.gz"

build() {
	CXXFLAGS="$CXXFLAGS -flto=auto -Wno-deprecated-declarations" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DWITH_TESTS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# manual doc install
	gzip -9n "$pkgdir"/usr/share/man/man*/*
}

check() {
	ctest --test-dir build --output-on-failure
}

cutechess_doc() {
	install_if="$pkgname=$pkgver-r$pkgrel docs"

	amove usr/share/man/man5
}

cli() {
	pkgdesc="Commandline interface for cutechess"

	amove usr/bin/cutechess-cli
}

cli_doc() {
	install_if="$pkgname-cli=$pkgver-r$pkgrel docs"

	amove usr/share/man/man6
}

sha512sums="
d6078d7ba30f735f4a12719f75e028fb990d7e6d4f5aebd3ba6295523513adf26725854c7d221dbb6c6a93cc8b4a7edd10c6d6cb1741678136367b63da08c471  cutechess-1.3.1.tar.gz
"
